package main

import (
	"github.com/stoewer/go-strcase"
	"gorm.io/driver/mysql"
	"gorm.io/gen"
	"gorm.io/gorm"
)

func main() {
	g := gen.NewGenerator(gen.Config{
		OutPath: "./internal/modular/system/dao",
		Mode:    gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
	})
	g.WithJSONTagNameStrategy(func(columnName string) (tagContent string) {
		tagContent = strcase.LowerCamelCase(columnName)
		return
	})

	g.WithDataTypeMap(map[string]func(columnType gorm.ColumnType) (dataType string){
		"bigint": func(columnType gorm.ColumnType) (dataType string) {
			if columnType.Name() == "deleted_at" {
				return "DeletedAt"
			}
			return "int64"
		},
	})

	gormdb, _ := gorm.Open(mysql.Open("root:123456@(127.0.0.1:3306)/go_admin?charset=utf8mb4&parseTime=True&loc=Local"))
	g.UseDB(gormdb)

	g.ApplyBasic(
		// Generate structs from all tables of current database
		g.GenerateAllTable()...,
	)
	// Generate the code
	g.Execute()
}
